package cn.javase.base.io._08_字节数组流;

import java.io.*;

public class _对象深克隆 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        User user = new User("张三", 23);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(user);
        oos.flush();
        oos.close();
        ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
        ObjectInputStream ois = new ObjectInputStream(bis);
        User user1 = (User) ois.readObject();
        user1.setName("李四");
        user1.setAge(11);
        System.out.println(user.getAge() + user.getName());
        System.out.println(user1.getAge() + user1.getName());
        ois.close();
    }
}
